package com.xiaoluo.listener;

import com.xiaoluo.common.queue.JobMonitor;
import com.xiaoluo.common.utils.ApplicationContextUtils;
import com.xiaoluo.common.utils.RedisUtils;

import com.xiaoluo.common.utils.Tools;
import com.xiaoluo.service.JobService;
import com.xiaoluo.service.ServerService;
import com.xl.property.PropertyEtcdConfigurer;
import org.springframework.web.context.support.WebApplicationContextUtils;
import redis.clients.jedis.JedisPool;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 * Created by Administrator on 2015/9/10.
 */
public class SpiderListener implements ServletContextListener {

    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        ApplicationContextUtils.setSpringContext(WebApplicationContextUtils.getWebApplicationContext(servletContextEvent.getServletContext()));
        RedisUtils.jedisPool = (JedisPool) ApplicationContextUtils.getBean("jedisPool");
        ApplicationContextUtils.jobService = (JobService) ApplicationContextUtils.getBean("jobService");
        ApplicationContextUtils.propertyConfigurer = (PropertyEtcdConfigurer) ApplicationContextUtils.getBean("propertyConfigurer");
        ApplicationContextUtils.serverService = (ServerService) ApplicationContextUtils.getBean("serverService");

        new Thread(new JobMonitor()).start();
   }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {

    }
}
